package com.yqkj.zysoft.upms.controller;


import  com.project.easy.common.util.collection.CollectionUtil;
import  com.project.easy.common.util.constants.SysModelConstant;
import  com.project.easy.common.util.constants.VersionConstant;
import  com.project.easy.common.util.dto.IdApiContextParam;
import  com.project.easy.common.util.dto.OneLongApiContextParam;
import  com.project.easy.common.util.dto.PageResDto;
import  com.project.easy.common.util.dto.R;
import  com.project.easy.common.util.dto.TwoApiContextParam;
import  com.project.easy.common.util.dto.TwoLongApiContextParam;
import com.project.easy.common.framework.web.annotation.ApiValidator;
import com.project.easy.common.log.annotation.Logging;
import com.project.easy.common.framework.web.controller.BaseController;

import com.yqkj.zysoft.upms.entity.FrameworkUser;
import com.yqkj.zysoft.upms.entity.dto.FrameWorkUserAddRequest;
import com.yqkj.zysoft.upms.entity.dto.FrameWorkUserDetailResponse;
import com.yqkj.zysoft.upms.entity.dto.FrameWorkUserUpdateRequest;
import com.yqkj.zysoft.upms.entity.dto.PageUserRequest;
import com.yqkj.zysoft.upms.entity.dto.VerifyCodeAccNoRequest;
import com.yqkj.zysoft.upms.service.IFrameworkUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  用户服务控制服务类
 * </p>
 *
 * @author GreatorMan.cool
 * @since 2022-09-15
 */
@RestController
@RequestMapping("/api/" + VersionConstant.ONE + "/upms/user")
public class FrameworkUserController extends BaseController {

    @Autowired
    private IFrameworkUserService iFrameworkUserService;

    /**
     * 修改密码
     * @param contextParam 参数
     * @return 返回数据
     */
    @PostMapping("/updatePassword")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> updatePassword(@RequestBody TwoApiContextParam contextParam) {
        return R.success(iFrameworkUserService.updatePassword(contextParam.getOne(), Long.valueOf(contextParam.getTwo())));
    }
    /**
     * 修改角色
     * @param contextParam 参数
     * @return 返回数据
     */
    @PostMapping("/updateRole")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> updateRole(@RequestBody TwoApiContextParam contextParam) {
        return R.success(iFrameworkUserService.updateRole(contextParam.getOne(), Long.valueOf(contextParam.getTwo())));
    }
    /**
     * 修改用户组
     * @param contextParam 参数
     * @return 返回数据
     */
    @PostMapping("/updateGroup")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> updateGroup(@RequestBody TwoLongApiContextParam contextParam) {
        return R.success(iFrameworkUserService.updateGroup(contextParam.getOne(), contextParam.getTwo()));
    }
    /**
     * 修改部门
     * @param contextParam 参数
     * @return 返回数据
     */
    @PostMapping("/updateDepart")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> updateDepart(@RequestBody TwoApiContextParam contextParam) {
        return R.success(iFrameworkUserService.updateDepart(contextParam.getOne(), Long.valueOf(contextParam.getTwo())));
    }
    /**
     * 详情
     * @param contextParam 参数
     * @return 返回数据
     */
    @PostMapping("/detail")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<FrameWorkUserDetailResponse> detail(@RequestBody OneLongApiContextParam contextParam) {
        return R.success(iFrameworkUserService.detail(contextParam.getKey()));
    }
    /**
     * 新增
     * @param frameWorkUserAddRequest 参数
     * @return 返回数据
     */
    @PostMapping("/add")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Long> add(@RequestBody FrameWorkUserAddRequest frameWorkUserAddRequest) {
        return R.success(iFrameworkUserService.add(frameWorkUserAddRequest));
    }
    /**
     * 修改
     * @param frameWorkUserUpdateRequest 参数
     * @return 返回数据
     */
    @PostMapping("/udpate")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> udpate(@RequestBody FrameWorkUserUpdateRequest frameWorkUserUpdateRequest) {
        return R.success(iFrameworkUserService.updateObject(frameWorkUserUpdateRequest));
    }
    /**
     * 列表
     * @param pageUserRequest 参数
     * @return 返回数据
     */
    @PostMapping("/pageList")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<PageResDto<FrameworkUser>> pageList(@RequestBody PageUserRequest pageUserRequest) {
        return R.success(iFrameworkUserService.pageList(pageUserRequest));
    }
    /**
     * 验证编码
     * @param verifyCodeAccNoRequest 参数
     * @return 返回数据
     */
    @PostMapping("/verifyCode")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> verifyCode(@RequestBody VerifyCodeAccNoRequest verifyCodeAccNoRequest) {
        return R.success(iFrameworkUserService.verifyCode(verifyCodeAccNoRequest));
    }
    /**
     * 删除
     * @param sysParamDto 参数
     * @return 返回数据
     */
    @PostMapping("/del")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> del(@RequestBody IdApiContextParam sysParamDto) {
        return R.success(this.del(iFrameworkUserService, v -> v::setHasDel,
                CollectionUtil.parseIds(sysParamDto.getIds())));
    }
    /**
     * 禁用
     * @param oneApiContextParam 参数
     * @return 返回数据
     */
    @PostMapping("/disAble")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> disAble(@RequestBody OneLongApiContextParam oneApiContextParam) {
        return R.success(this.iFrameworkUserService.disAble(oneApiContextParam.getKey()));
    }
    /**
     * 启用
     * @param oneApiContextParam 参数
     * @return 返回数据
     */
    @PostMapping("/able")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> able(@RequestBody OneLongApiContextParam oneApiContextParam) {
        return R.success(this.iFrameworkUserService.able(oneApiContextParam.getKey()));
    }
}
